package com.lianzhihui.romeex.mvp.model;

import android.content.Context;

import com.lianzhihui.romeex.net.HttpManager;
import com.lianzhihui.romeex.net.HttpManagerCallback;
import com.lianzhihui.romeex.net.ResultData;
import com.lianzhihui.romeex.utils.MathUtil;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.HttpParams;

import static com.lianzhihui.romeex.config.AppConstants.BASE_ZERO;
import static com.lianzhihui.romeex.net.APIConstant.EXTRACT;
import static com.lianzhihui.romeex.net.APIConstant.PLEDGE;

/**
 * Description: 质押,提取 业务
 * Author: RAMON
 * CreateDate: 11/30/20 2:17 PM
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class PledgeModelImp {

    Context context;
    PledgeInterface callback;

    public PledgeModelImp(Context context, PledgeInterface callback) {
        this.context = context;
        this.callback = callback;
    }

    /**
     * 质押
     *
     * @param value 质押数量
     */
    public void pledge(String value) {

        HttpParams params = new HttpParams();
        double valueDouble = Double.parseDouble(value);
        Double valueLong = MathUtil.multiply(valueDouble,BASE_ZERO);

        params.put("pledgeBalance", valueLong.longValue()+"");

        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                callback.onPledgeSuccess();
            }

            @Override
            public void onError(ApiException e) {
                callback.onPledgeFail(e.getMessage());
            }
        }).post(PLEDGE, params);

    }

    /**
     * 提取
     */
    public void extract() {
        HttpParams params = new HttpParams();
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                callback.onExtractSuccess();
            }

            @Override
            public void onError(ApiException e) {
                callback.onExtractFail(e.getMessage());
            }
        }).post(EXTRACT, params);
    }

}
